﻿//JumbotCms_4.1 Final
using System;
using System.Web;
using System.Data;
using Jumbot.DataOper;
using JumbotCms.DataObject;
using JumbotCms.Common;
namespace JumbotCms.Common
{
    public class GetLinkPath : BasicPage
    {
        //临时频道信息
        private Channel _Channel;
        public GetLinkPath()
        {
            site = (Site)System.Web.HttpContext.Current.Application["System:Info"];
        }
        /// <summary>
        /// 链接到频道首页
        /// </summary>
        public string Channel(bool ishtml, DbOperHandler doh, string ccId)
        {
            _Channel = new Channel();
            _Channel.GetAllColumn(ccId, doh);
            if (!_Channel.IsOut)
            {
                string TempUrl = PageFormat.Channel(site.Dir, site.UrlReWriter);
                TempUrl = TempUrl.Replace("<#SiteDir#>", site.Dir);
                TempUrl = TempUrl.Replace("<#SiteStaticExt#>", site.StaticExt);
                TempUrl = TempUrl.Replace("<#ChannelId#>", ccId);
                TempUrl = TempUrl.Replace("<#ChannelDir#>", _Channel.Dir);
                return TempUrl;
            }
            else
                return _Channel.OutUrl;
        }
        /// <summary>
        /// 链接到栏目页
        /// </summary>
        public string Class(int page, bool ishtml, DbOperHandler doh, string ccId, string cId)
        {
            Class _Class = new Class();
            _Class.GetPartColumn(cId, doh);
            if (!_Class.IsOut)
            {
                _Channel = new Channel();
                _Channel.GetPartColumn(ccId, doh);
                string TempUrl;
                TempUrl = PageFormat.Class(ishtml, site.Dir, site.UrlReWriter, page);
                TempUrl = TempUrl.Replace("<#SiteDir#>", site.Dir);
                TempUrl = TempUrl.Replace("<#SiteStaticExt#>", site.StaticExt);
                TempUrl = TempUrl.Replace("<#ChannelId#>", ccId);
                TempUrl = TempUrl.Replace("<#ChannelDir#>", _Channel.Dir.ToLower());
                TempUrl = TempUrl.Replace("<#ChannelType#>", _Channel.Type.ToLower());
                TempUrl = TempUrl.Replace("<#id#>", cId);
                if (page > 0) TempUrl = TempUrl.Replace("<#page#>", page.ToString());
                return TempUrl;
            }
            else
                return _Class.OutUrl;
        }
        /// <summary>
        /// 链接到RSS页
        /// </summary>
        public string Rss(int page, bool ishtml, DbOperHandler doh, string ccId, string cId)
        {
            _Channel = new Channel();
            _Channel.GetPartColumn(ccId, doh);
            string TempUrl = PageFormat.Rss(ishtml, site.Dir, site.UrlReWriter, page);
            TempUrl = TempUrl.Replace("<#SiteDir#>", site.Dir);
            TempUrl = TempUrl.Replace("<#SiteStaticExt#>", site.StaticExt);
            TempUrl = TempUrl.Replace("<#ChannelId#>", ccId);
            TempUrl = TempUrl.Replace("<#ChannelDir#>", _Channel.Dir.ToLower());
            TempUrl = TempUrl.Replace("<#ChannelType#>", _Channel.Type.ToLower());
            TempUrl = TempUrl.Replace("<#id#>", cId);
            if (page > 0) TempUrl = TempUrl.Replace("<#page#>", page.ToString());
            return TempUrl;
        }
        /// <summary>
        /// 链接到内容页
        /// </summary>
        public string View(int page, bool ishtml, DbOperHandler doh, string ccId, string aId)
        {
            _Channel = new Channel();
            _Channel.GetPartColumn(ccId, doh);
            doh.Reset();
            doh.ConditionExpress = "ChannelId=" + ccId + " and Id=" + aId;
            string _date = doh.GetValue("jcms_module_" + _Channel.Type, "AddDate").ToString();
            string TempUrl = PageFormat.View(ishtml, site.Dir, site.UrlReWriter, page);
            TempUrl = TempUrl.Replace("<#SiteDir#>", site.Dir);
            TempUrl = TempUrl.Replace("<#SiteStaticExt#>", site.StaticExt);
            TempUrl = TempUrl.Replace("<#ChannelId#>", ccId);
            TempUrl = TempUrl.Replace("<#ChannelDir#>", _Channel.Dir.ToLower());
            TempUrl = TempUrl.Replace("<#ChannelType#>", _Channel.Type.ToLower());
            TempUrl = TempUrl.Replace("<#id#>", aId);
            if (_date != "")
            {
                TempUrl = TempUrl.Replace("<#year#>", DateTime.Parse(_date).ToString("yyyy"));
                TempUrl = TempUrl.Replace("<#month#>", DateTime.Parse(_date).ToString("MM"));
                TempUrl = TempUrl.Replace("<#day#>", DateTime.Parse(_date).ToString("dd"));
            }
            if (page > 0) TempUrl = TempUrl.Replace("<#page#>", page.ToString());
            return TempUrl;
        }
    }
}
